/* ==================================================================   
 * Created [2009-4-27 下午11:32:55] by Jon.King 
 * ==================================================================  
 * TSS 
 * ================================================================== 
 * mailTo:jinpujun@hotmail.com
 * Copyright (c) Jon.King, 2009-2012 
 * ================================================================== 
 */

package com.jinhe.tss.component.log.maintain;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.jinhe.tss.component.log.LogDto;
import com.jinhe.tss.component.log.entity.Log;
import com.jinhe.tss.core.persistence.ICommonDao;
import com.jinhe.tss.core.util.BeanUtil;
 
public class LogServiceImpl implements LogService {
    
    @Autowired private ICommonDao dao;

    public void createLog(LogDto dto){
        Log log = new Log();
        BeanUtil.copy(log, dto);
        dao.create(log);
    }
    
    public void createLogs(List<LogDto> logs){
        for(LogDto dto : logs){
            Log log = new Log();
            BeanUtil.copy(log, dto);
            dao.createWithoutFlush(log);
        }
        dao.flush();
    }

    public List<?> getAllApps() {
        return dao.getEntities("select distinct o.appCode from Log o group by o.appCode");
    }

    public Object[] getLogsByCondition(LogQueryCondition condition) {
        String orderBy = " order by o.operateTime desc";
        return dao.getEntities(condition, "Log", orderBy);
        
    }

    public Log getLogById(Long id) {
        return (Log) dao.getEntity(Log.class, id);
    }
}

